/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.bingoogolapple.badgeview.demo.widget;

import cn.bingoogolapple.badgeview.BGABadgeViewHelper;
import cn.bingoogolapple.badgeview.BGABadgeable;
import cn.bingoogolapple.badgeview.BGADragDismissDelegate;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.RadioButton;
import ohos.agp.render.Canvas;
import ohos.app.Context;
import ohos.media.image.PixelMap;
import ohos.multimodalinput.event.TouchEvent;

/**
 * 自定义 RadioButton
 *
 * @since 2021-04-21
 */
public class BgaBadgeRadioButton extends RadioButton implements BGABadgeable, Component.TouchEventListener,
        Component.DrawTask {
    private BGABadgeViewHelper mBadgeViewHelper;

    /**
     * BgaBadgeRadioButton
     *
     * @param context Context
     */
    public BgaBadgeRadioButton(Context context) {
        super(context, null);
    }

    /**
     * BgaBadgeRadioButton
     *
     * @param context Context
     * @param attrSet AttrSet
     */
    public BgaBadgeRadioButton(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    /**
     * BgaBadgeRadioButton
     *
     * @param context Context
     * @param attrSet AttrSet
     * @param styleName String
     */
    public BgaBadgeRadioButton(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        mBadgeViewHelper = new BGABadgeViewHelper(this, context, attrSet, BGABadgeViewHelper.BadgeGravity.RightTop);
        addDrawTask(this);
        setTouchEventListener(this);
    }

    /**
     * onTouchEvent
     *
     * @param component
     * @param touchEvent
     * @return boolean
     */
    @Override
    public boolean onTouchEvent(Component component, TouchEvent touchEvent) {
        return mBadgeViewHelper.onTouchEventHelper(touchEvent);
    }

    /**
     * callSuperOnTouchEvent
     *
     * @param event
     * @return boolean
     */
    @Override
    public boolean callSuperOnTouchEvent(TouchEvent event) {
        return false;
    }

    /**
     * onDraw
     *
     * @param component Component
     * @param canvas Canvas
     */
    @Override
    public void onDraw(Component component, Canvas canvas) {
        mBadgeViewHelper.drawBadge(canvas);
    }

    /**
     * showCirclePointBadge
     */
    @Override
    public void showCirclePointBadge() {
        mBadgeViewHelper.showCirclePointBadge();
    }

    /**
     * showTextBadge
     *
     * @param badgeText
     */
    @Override
    public void showTextBadge(String badgeText) {
        mBadgeViewHelper.showTextBadge(badgeText);
    }

    /**
     * hiddenBadge
     */
    @Override
    public void hiddenBadge() {
        mBadgeViewHelper.hiddenBadge();
    }

    /**
     * showDrawableBadge
     *
     * @param bitmap
     */
    @Override
    public void showDrawableBadge(PixelMap bitmap) {
        mBadgeViewHelper.showDrawable(bitmap);
    }

    /**
     * setDragDismissDelegate
     *
     * @param delegate
     */
    @Override
    public void setDragDismissDelegate(BGADragDismissDelegate delegate) {
        mBadgeViewHelper.setDragDismissDelegate(delegate);
    }

    /**
     * isShowBadge
     *
     * @return boolean
     */
    @Override
    public boolean isShowBadge() {
        return mBadgeViewHelper.isShowBadge();
    }

    /**
     * isDraggable
     *
     * @return boolean
     */
    @Override
    public boolean isDraggable() {
        return mBadgeViewHelper.isDraggable();
    }

    /**
     * isDragging
     *
     * @return boolean
     */
    @Override
    public boolean isDragging() {
        return mBadgeViewHelper.isDragging();
    }

    /**
     * getBadgeViewHelper
     *
     * @return BGABadgeViewHelper
     */
    @Override
    public BGABadgeViewHelper getBadgeViewHelper() {
        return mBadgeViewHelper;
    }

    /**
     * getComponentRect
     *
     * @return Component
     */
    @Override
    public Component getComponentRect() {
        return this;
    }

    /**
     * setComponent
     *
     * @param topComponent Component
     */
    @Override
    public void setComponent(Component topComponent) {
        mBadgeViewHelper.setComponent(topComponent);
    }

    /**
     * setDrawTask
     *
     * @param canvas Canvas
     */
    @Override
    public void setDrawTask(Canvas canvas) {
        mBadgeViewHelper.setMDrawTask(canvas);
    }
}
